/**
* @Title: integrityMedicalDesc_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
 * Company:中国平安
*
* @Project HIMS-FWA
* @author EX-XIEYUWEN001
* @date 2014年10月29日 下午14:36:25
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('IntegrityMedicalDescCtrl', ['$scope','$stateParams','BaseURL','Modal','FwaTabsetService','IntegrityMedicalService',
	                                function($scope,$stateParams,baseUrl,Modal,FwaTabsetService,IntegrityMedicalService){
		$scope.form = {};
		$scope.form.date = {};
		var params = function (){
			var startDate = "";
			if($stateParams.startDate&&!angular.isUndefined($stateParams.startDate)){
				startDate = $stateParams.startDate;
			}
			var endDate="";
			if($stateParams.endDate&&!angular.isUndefined($stateParams.endDate)){
				endDate = $stateParams.endDate;
			}
			var doctorCode="";
			if($stateParams.doctorCode&&!angular.isUndefined($stateParams.doctorCode)){
				doctorCode = $stateParams.doctorCode;
			}
			var params = {
					startDate:startDate,
					endDate:endDate,
					doctorCode:doctorCode
			}
			return params;
		}
		$scope.queryIntegrityMedicalDesc = function (params){
			IntegrityMedicalService.getIntegrityMedicalDesc(params).
			success(function(res){
				$scope.tableData = res.integrityMedicalDesc;
				$scope.happenDate =  $stateParams.startDate+'~'+$stateParams.endDate;
				$scope.doctorName =  $stateParams.doctorName;
				$scope.certificateNo =  $stateParams.certificateNo;
			});
		}
		$scope.queryIntegrityMedicalDesc(params());
		var cellTemplate = 
			'<td>'+
				'<a  ng-click="queryTo(data.healthcareProviderCode,data.certificateNo,data.name,data.healthcareProviderName,data.fullAddress)">查询详情</a>'+
			'</td>';
		$scope.columns = [
//		      		    {label:'医生姓名',map:'name', width:'10%'},
//		      		    {label:'身份证号',map:'certificateNo', width:'20%'},
						{label:'机构名称',map:'healthcareProviderName', width:'10%'},
		      		    {label:'机构编号',map:'healthcareProviderCode', width:'10%'},
		      		    {label:'机构地址',map:'fullAddress', width:'20%'},
		      		    {label:'执业时间',map:'qualifiedDate', width:'10%'},
		      		    {label:'违规记分值',map:'violationsScores', width:'18%',cellClass:'text-center'},
		      		    {label:'违规记分值明细',map:'orgCode', width:'18%',cellClass:'text-center', cellTemplate:cellTemplate},
		      		    {label:'备注',map:'remark',width:'14%'}
		      		 ];
	
		$scope.queryTo = function (orgCode,certificateNo,doctorName,orgName,fullAddress){
			 FwaTabsetService.selectTab('integrityMedicalMark.info',{
				 		flat:"1",//1.明细查询
					 	orgCode:orgCode,
					 	doctorName:doctorName,
					 	certificateNo:certificateNo,
					 	orgName:orgName,
					 	fullAddress:fullAddress,
					 	startDate:$stateParams.startDate,
						endDate:$stateParams.endDate,
						doctorCode:$stateParams.doctorCode
				 	},false);
		}
		$scope.onReturn = function (){
			FwaTabsetService.selectTab('integrityMedical',null,false);
		}
		// 导出
		$scope.onExport = function() {
    		$scope.loading = true;
			var par = params();
			var startDate = par.startDate,
			endDate = par.endDate,
			doctorCode = par.doctorCode;
			var url= baseUrl+"integrityMedical/integrityMedicalDescReport.do?startDate="+startDate
			+"&endDate="+endDate+"&doctorCode="+doctorCode+"&excelName="+"医务人员纪录_明细导出";
//			var url= baseUrl+"integrityMedical/integrityMedicalDescReport.do?excelName="+"医务人员纪录_明细导出";
			window.location.href = url;
    		$scope.loading = false;
		}
		
	}]);
})();